package com.jwdf.uda.ui.adapter;

import android.content.Context;
import android.view.ViewGroup;

import com.jwdf.uda.R;
import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.event.ReplyDetailItemClickEvent;
import com.jwdf.uda.ui.adapter.item.ReplyDetailItem;
import com.jwdf.uda.ui.adapter.viewholder.ReplyCmtImageViewHolder;
import com.jwdf.uda.ui.adapter.viewholder.ReplyCmtTextViewHolder;

import java.util.List;

/**
 * Created by Administrator on 2016/10/17.
 */
public class ReplyCmtAdapter extends AbsAdapter<ReplyDetailItem> {
    private static final int ITEM_TEXT = 0;
    private static final int ITEM_IMAGE_TEXT = 1;

    public ReplyCmtAdapter(Context context) {
        super(context);
    }

    @Override
    protected AbsViewHolder onCreateViewHolder(ViewGroup parent, int itemType) {
        switch (itemType) {
            case ITEM_IMAGE_TEXT:
                return new ReplyCmtImageViewHolder(mInflater.inflate(R.layout.item_reply_comment_image, parent, false));
            default:
                return new ReplyCmtTextViewHolder(mInflater.inflate(R.layout.item_reply_comment_txt, parent, false));
        }
    }

    @Override
    public int getItemViewType(int position) {
        PbBean.PbBaseComment comment = getItem(position).comment;
        List<PbBean.PbImage> imageList = comment.getImageListList();
        return imageList == null || imageList.size() <= 0 ? ITEM_TEXT : ITEM_IMAGE_TEXT;
    }

    @Override
    public int getViewTypeCount() {
        return 2;
    }

    public void onEventMainThread(ReplyDetailItemClickEvent event) {
        if (event != null) {
            ReplyDetailItem eventItem = event.getItem();
            if (ReplyDetailItemClickEvent.EVENT_COMMENT_LIKE_CLICK == event.getEvent()) {
                for (ReplyDetailItem item : mData) {
                    if (item.commentId == eventItem.commentId) {
                        item.isLikeComment = eventItem.isLikeComment;
                        item.commentLikeCount = eventItem.commentLikeCount;
                        notifyDataSetChanged();
                        break;
                    }
                }
            }
        }
    }
}
